<template>
  <div class="login-box">
    <div class="box">
      <h3 align="center">梦学谷会员管理系统</h3>
      <el-form
        :model="ruleForm"
        :rules="rules"
        ref="ruleForm"
        label-width="55px"
        class="demo-ruleForm"
      >
        <el-form-item label="账号" prop="username">
          <el-input
            placeholder="请输入账号"
            v-model.trim="ruleForm.username"
          ></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="password">
          <el-input
            type="password"
            placeholder="请输入密码"
            v-model.trim="ruleForm.password"
            show-password
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm">登录</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import userApi from '../../api/user'
export default {
  data() {
    return {
      ruleForm: {
        username: "",
        password: "",
      },
      rules: {
        username: [
          { required: true, message: "请输入账号", trigger: "blur" },
          {
            min: 3,
            max: 10,
            message: "长度在 3 到 10 个字符",
            trigger: "blur",
          },
        ],
        password: [{ required: true, message: "请输入密码", trigger: "blur" }],
      },
    };
  },
  mounted() {},
  methods: {
    submitForm() {
      this.$refs["ruleForm"].validate((valid) => {
        if (valid) {
          this.$store.dispatch('login',this.ruleForm).then(response=>{
            if(response.data.flag){
              this.$message.success(response.data.message)
              this.$router.push('/layout')
            }
          })
        }else{
          this.$message.error(response.data.message)
        }
      });
    },
  },
};
</script>

<style scoped lang="scss">
.login-box {
  width: 100%;
  height: 100%;
  background-image: url("../../assets/login.jpg");
  background-size: 100% 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.box {
  width: 350px;
  padding: 30px;
  background-color: rgba(255, 255, 255, 0.8);
  border-radius: 20px;
  h3 {
    margin: 0;
    margin-bottom: 20px;
    font-size: 18px;
    font-weight: bold;
  }
}
</style>
